 
// This do-file cleans variables, standardizes job titles, country names, add labels etc. and saves analysis.dta

use "$root/input/aid_finaldataset.dta", clear

* -------------------------------------------------------------------		
// 1.	Cleaning treatment arms from endorsement and preamble
* -------------------------------------------------------------------		

	// Destring and gen treatment arms
	destring preamble, 	  gen(treat_preamble)
	destring endorsement, gen(treat_endorsement)

	//Generate treatment preamble dummy (control vs. treat)
	gen 	treat_preamble_dummy=(treat_preamble!=1)
	lab var treat_preamble_dummy "Survey Funded by DFID/Gates/ADB"
	
	//recode endorsement
	recode treat_endorsement 6=0
	
	// Label treatment arms
	label define treat_preamble 	1 "Control" 2 "DFID" 3 "Gates" 4 "ADB", replace
	label define treat_endorsement  1 "WB" 2 "UNESCO" 3 "UNICEF" 4 "GPE" 5 "Gates" 0 "Control", replace
	
	label values treat_preamble 	treat_preamble
	label values treat_endorsement 	treat_endorsement


	// Generate control and treatment in endorsement experiment
	gen 	treat_endorsement_dummy=1 if inlist(treat_endorsement,1,2,3,4,5)
	replace treat_endorsement_dummy=0 if treat_endorsement==0

* -------------------------------------------------------------------		
// 2.	Dummies for countries where officials studied:
* -------------------------------------------------------------------		

	gen studied_uk=0
	gen studied_usa=0
	gen studied_oecd=0
	gen studied_france=0
	gen studied_china=0
	gen studied_eu=0
	gen studied_canada=0
	gen studied_germany=0
	
	forval n=1/7 {
		replace studied_uk  =1 if country_studied`n'=="UK"
		replace studied_usa =1 if country_studied`n'=="USA"
		replace studied_france=1 if country_studied`n'=="France"
		replace studied_china=1 if country_studied`n'=="China"
		replace studied_canada=1 if country_studied`n'=="Canada"
		replace studied_germany=1 if country_studied`n'=="Germany"
		replace studied_eu=1 if inlist(country_studied`n',"Austria","Belgium","Denmark","Finland","France","Germany","Ireland","Italy","Netherlands")
		replace studied_eu=1 if inlist(country_studied`n',"Norway","Portugal","Sweden")
		replace studied_oecd=1 if inlist(country_studied`n',"Australia","Austria","Belgium","Canada","Denmark","Finland","France","Germany","Ireland")
		replace studied_oecd=1 if inlist(country_studied`n',"Italy","Japan","Netherlands","New Zealand","Norway","Portugal","Sweden","UK","USA")
		replace studied_oecd=1 if inlist(country_studied`n',"Switzerland")
		}

	label var studied_oecd "OECD"
	label var studied_uk   "UK"
	label var studied_usa  "USA"
	label var studied_eu  "EU"
	label var studied_france  "France"
	label var studied_china  "China"
	label var studied_canada  "Canada"
	label var studied_germany "Germany"
	

* -------------------------------------------------------------------		
// 3.	National and Global crisis variables:
* -------------------------------------------------------------------	

 ren globalcrisis globalcrisis_s
 ren nationalcrisis nationalcrisis_s

 encode globalcrisis_s, gen(globalcrisis)
 encode nationalcrisis_s, gen(nationalcrisis)

	// Categorical values of agreement with statements
	recode globalcrisis 1=3 2=4 3=2 4=5 5=1
	recode nationalcrisis 1=3 2=4 3=2 4=5 5=1

	label define likert 1 "Strongly Disagree" 2 "Somewhat Disagree" 3 "Neither" 4 "Somewhat Agree" 5 "Strongly Agree"
	label values globalcrisis nationalcrisis "likert"
	label var globalcrisis   "There is a global learning crisis" 
	label var nationalcrisis "There is a national learning crisis" 
	
	// Dummy if agrees with statements
	gen globalcrisis_binary=(inlist(globalcrisis,4,5))
	gen nationalcrisis_binary=(inlist(nationalcrisis,4,5))
	lab var globalcrisis_binary		"Agree there is a global learning crisis (0/1)"
	lab var nationalcrisis_binary	"Agree there is a national learning crisis (0/1)"	
	
* -------------------------------------------------------------------		
// 4.	Fragmentation:
* -------------------------------------------------------------------	
	
	// Generating categorical values instead of string
	foreach var of varlist frag* {
	rename `var' `var'_s
	encode `var'_s, gen(`var')
	}

	// Recode values so neither is 3, not 1
	foreach var of varlist frag_report_burden frag_coordination frag_diversity_good frag_fin_well_directed frag_nonfin_well_directed {
	recode `var' 1=3 2=4 3=2 4=5 5=1
	}
	
	label values frag_report_burden frag_coordination frag_diversity_good frag_fin_well_directed frag_nonfin_well_directed "likert"
	
	lab var frag_report_burden 			"Its a burden reporting to DPs"
	lab var frag_coordination 			"Lack of DP coordination"
	lab var frag_diversity_good 		"Diversity of DP is good"
	lab var frag_fin_well_directed 		"DP Financial Resources Well Directed"
	lab var frag_nonfin_well_directed 	"DP Non-Financial Resources Well Directed"

	//principal component analysis 
	pca frag_report_burden frag_coordination frag_diversity_good frag_fin_well_directed frag_nonfin_well_directed
	tempvar satisfaction_pca
	predict `satisfaction_pca'
	egen satisfaction=std(`satisfaction_pca')
	
* -------------------------------------------------------------------		
// 5.	SDG's importance rating and order:
* -------------------------------------------------------------------	

// (IIIB) (d) sdgs labels	
/*	// Full Labels
	label var sdg_secondary "All children complete secondary school"
	label var sdg_ecd 		"All children receive quality ECD and pre-primary"
	label var sdg_tvet 		"All children have option of TVET"
	label var sdg_empl 		"Increase youth and adults with relevant employment skills"
	label var sdg_gender 	"Eliminate gender disparities"
	label var sdg_adult 	"Adult literacy and numeracy"
	label var sdg_sust 		"Skills for sustainable development"
	label var sdg_found 	"All children achieve foundational skills by age 10"
*/

	// Keep only the first 3
		foreach var of varlist sdg_* {
		destring `var', replace
		replace `var'=. if `var'>3
		recode `var' 3=1 2=2 1=3 .=0
	}

	// Generate var of first most important, second most important
	// and third most important
	forval n=1/3{
		gen sdg_order`n'=1 if sdg_secondary==`n'
		replace sdg_order`n'=2 if sdg_ecd==`n'
		replace sdg_order`n'=3 if sdg_tvet==`n'
		replace sdg_order`n'=4 if sdg_empl==`n'
		replace sdg_order`n'=5 if sdg_gender==`n'
		replace sdg_order`n'=6 if sdg_adult==`n'
		replace sdg_order`n'=7 if sdg_sust==`n'
		replace sdg_order`n'=8 if sdg_found==`n'
	}

	// Short Labels
	lab var sdg_ecd "ECD"	
	lab var sdg_secondary "Secondary"
	lab var sdg_empl "Employment"
	lab var sdg_found "Foundational Skills"
	lab var sdg_tvet "TVET"
	lab var sdg_sust "Skills for Sustainability"
	lab var sdg_gender "Gender Equality"
	lab var sdg_adult "Adult Literacy"
		
	label define sdg_order 1 "All children complete secondary school" ///
		  2 "All children receive quality ECD and pre-primary" 3 "All children have option of TVET" 4 "Increase youth and adults with relevant employment skills" ///
		  5 "Eliminate gender disparities" 6 "Adult literacy and numeracy" 7 "Skills for sustainable development" 8  "All children achieve foundational skills by age 10"
	label values sdg_order1 sdg_order2 sdg_order3 sdg_order

foreach var of varlist sdg_secondary sdg_ecd sdg_tvet sdg_empl sdg_gender sdg_adult sdg_sust sdg_found{
	gen 	`var'_top=0
	replace `var'_top=1 if `var'==1
	gen 	`var'_2nd=0
	replace `var'_2nd=1 if `var'==2	
	gen 	`var'_3rd=0
	replace `var'_3rd=1 if `var'==3	
	gen 	`var'_top3=0
	replace `var'_top3=100 if inlist(`var',1,2,3)	
}

* -------------------------------------------------------------------		
// 6.	Human Capital Production Function:
* -------------------------------------------------------------------	

// Generating returns results
	
	foreach sex in girl boy{
	foreach income in rich poor{
	foreach iq in high low{
	
	replace earn_`sex'_`income'_`iq'_second  = . if earn_`sex'_`income'_`iq'_second==0
	replace earn_`sex'_`income'_`iq'_primary = . if earn_`sex'_`income'_`iq'_primary==0
	gen returns_`sex'_`income'_`iq' = (earn_`sex'_`income'_`iq'_second - ///
									   earn_`sex'_`income'_`iq'_primary) / ///
									   earn_`sex'_`income'_`iq'_primary if ///
									   earn_`sex'_`income'_`iq'_second!=. & ///
									   earn_`sex'_`income'_`iq'_primary!=.
	replace returns_`sex'_`income'_`iq' = . if returns_`sex'_`income'_`iq'>100 | returns_`sex'_`income'_`iq'<0
	}
	} 
	}	

// Generating returns results	overall (no sex breakdown)
	foreach var of varlist returns*{
		winsor2 `var',   replace cuts(2.5 97.5)		
	}

	gen returns_male=. 
	gen returns_poor_low=.
	gen returns_poor_high=.
	gen returns_rich_low=.
	gen returns_rich_high=.

	foreach var of varlist returns_girl* {
	replace returns_male=0 if `var'!=.
	}
	foreach var of varlist returns_boy* {
	replace returns_male=1 if `var'!=.
	}

	replace returns_poor_low  = returns_boy_poor_low  if returns_male==1
	replace returns_poor_high = returns_boy_poor_high if returns_male==1
	replace returns_rich_low  = returns_boy_rich_low  if returns_male==1
	replace returns_rich_high = returns_boy_rich_high if returns_male==1

	replace returns_poor_low  = returns_girl_poor_low  if returns_male==0
	replace returns_poor_high = returns_girl_poor_high if returns_male==0
	replace returns_rich_low  = returns_girl_rich_low  if returns_male==0
	replace returns_rich_high = returns_girl_rich_high if returns_male==0

	egen returns_poor = rowmean(returns_poor_low returns_poor_high)
	egen returns_rich = rowmean(returns_rich_low returns_rich_high)
	egen returns_low  = rowmean(returns_poor_low returns_rich_low)
	egen returns_high = rowmean(returns_rich_high returns_poor_high)

	gen returns_girl_poor=returns_girl_poor_high+returns_girl_poor_low
	gen returns_girl_rich=returns_girl_rich_high+returns_girl_rich_low
	
	global returns_4 earn* returns*

	label define boys 1 "Boys" 0 "Girls"	
	label values returns_male boys

	gen returns_wealth=(returns_poor_low+returns_rich_low)/(returns_poor_high+returns_rich_high)

	egen 	returns_estimate_male   = rowmean(returns_poor_low returns_poor_high returns_rich_low returns_rich_high) if returns_male==1
	egen 	returns_estimate_female = rowmean(returns_poor_low returns_poor_high returns_rich_low returns_rich_high) if returns_male==0
	replace returns_estimate_male   = returns_estimate_male*100
	replace returns_estimate_female = returns_estimate_female*100
		
		
	gen 	returns_estimate=returns_estimate_male
	replace returns_estimate=returns_estimate_female if returns_estimate==.	
	replace returns_estimate=100 if returns_estimate==.
	lab var returns_estimate "Estimate of Returns"
	
	egen 	returns_std=std(returns_estimate)
	lab var returns_std "Belief about LM returns (z-score)"	

* -------------------------------------------------------------------		
// 7.	Evidence use (belief updating experiment) :
* -------------------------------------------------------------------	
		
	// Categorical variable for which study was randomly assigned 
	destring script, gen(treat_script)
	label define treat_script 1 "Kenya RCT" 2 "Kenya" 3 "SA RCT" 4 "SA" 5 "USA RCT" 6 "USA", replace	
	label values treat_script treat_script
	
	// Generate rct and non-rct from study
	gen 	treat_script_rct=0 if inlist(treat_script,2,4,6)
	replace treat_script_rct=1 if inlist(treat_script,1,3,5)
	label define treat_script_rct 0 "The study was carried out in ..." 1 "The study was an RCT carried out in ...", replace
	label values treat_script_rct treat_script_rct
	
	// Generate country id of study
	gen 	treat_script_country=0 if inlist(treat_script,5,6)
	replace treat_script_country=1 if inlist(treat_script,3,4)
	replace treat_script_country=2 if inlist(treat_script,1,2)
	
	// Label study id in evidence use experiment
	label define treat_script_country 0 "... the US with 170 schools" 1 "... South Africa with 50 schools" 2 "... Kenya with over 800 schools", replace
	label values treat_script_country treat_script_country
	
	// Generate scale of 0-4 of on effect size
	gen 	script_prior=0 if script_priorr=="No effect"
	replace script_prior=1 if script_priorr=="Small effect"
	replace script_prior=2 if script_priorr=="Medium effect"
	replace script_prior=3 if script_priorr=="Large effect"
	replace script_prior=4 if script_priorr=="Very large effect"

	//Generate one variable to capture posterior belief of effect size on scale of 0-4
	gen 	script_posterior=0 if script_posterior1=="No effect"|script_posterior2=="No effect"|script_posterior3=="No effect"
	replace script_posterior=1 if script_posterior1=="Small effect"|script_posterior2=="Small effect"| ///
									script_posterior3=="Small effect"
	replace script_posterior=2 if script_posterior1=="Medium effect"|script_posterior2=="Medium effect"| ///
									script_posterior3=="Medium effect"
	replace script_posterior=3 if script_posterior1=="Large effect"|script_posterior2=="Large effect"| ///
									script_posterior3=="Large effect"
	replace script_posterior=4 if script_posterior1=="Very large effect"|script_posterior2=="Very large effect"| /// 
									script_posterior3=="Very large effect"
	
	
	// Generate true effect of studies (SA=Very large; US & Kenya=Medium)
	gen 	trueeffect=4 if treat_script_country==2
	replace trueeffect=2 if inlist(treat_script_country,1,0)

	//Calculate prior and posterior absolute gaps
	gen gap_prior=abs(trueeffect-script_prior)
	gen gap_posterior=abs(trueeffect-script_posterior)

	//Calculate belief update 
	gen updating=gap_prior-gap_posterior
	
	//Update sd calculation
	egen 	update_z=std(updating)
	lab var update_z "Belief Updating (Z-Score)"
	
		// Sample size from the study
		gen 	schoolsize=170 if treat_script_country==0
		replace schoolsize=50  if treat_script_country==1
		replace schoolsize=800 if treat_script_country==2
		replace schoolsize=schoolsize/100
		
		// Location of the study
		gen 	developing=0 if treat_script_country==0
		replace developing=1 if inlist(treat_script_country,1,2)

	//labels:
	label define effect 0 "No effect" 1 "Small effect" 2 "Medium effect" 3 "Large effect" 4 "Very large effect"

	label values script_prior script_posterior effect
		lab var script_demand "Copy of Study"
		lab var treat_script_rct "Study was RCT" 
		lab var schoolsize "N of schools (100s)" 
		lab var developing "Developing Country"
		lab var script_posterior "Belief about scripted lessons (0-4 scale)"
		
	global evidence_5 script_prior script_posterior script_demand* trueeffect gap_* updating

* -------------------------------------------------------------------		
// 8.	Role models (countries officials look to)
* -------------------------------------------------------------------	

	// Dummy for each country:
	forval n=1/3{
	levelsof rolemodel`n', local(country)
	foreach c in `country' {
	cap gen rolemodel_`c'=0 
	replace rolemodel_`c'=100 if rolemodel`n'=="`c'"
	lab var rolemodel_`c' "`c'"
	}
	}

	foreach var of varlist rolemodel_*{
	ren `var', lower 
	}
		
	replace rolemodel_uk=rolemodel_uk/100 
	replace rolemodel_usa=rolemodel_usa/100 

* -------------------------------------------------------------------		
// 9.	Development partners importance rating and time spent:
* -------------------------------------------------------------------	
	
	//time spent with donors
	foreach var of varlist dp*time {
	rename `var' `var'_s
	}
	
	forval n=1/3{
	gen dp`n'time=.
	replace dp`n'time=1 if dp`n'time_s=="Not relevant"
	replace dp`n'time=2 if dp`n'time_s=="Too much time"
	replace dp`n'time=3 if dp`n'time_s=="Enough time"
	replace dp`n'time=4 if dp`n'time_s=="Not enough time"
	
	labmask dp`n'time, values(dp`n'time_s)
	}	

	// Dummies for mentioning specific donor, donor specific rating and time spent.
	foreach donor in ADB GPE UNICEF UNESCO World_Bank Australia DFID EU France Germany JICA New_Zealand USAID{
		gen mention_`donor'=0
		gen rating_`donor'=0
		gen time_`donor'=.
		forval n=1/3{
			replace rating_`donor'=dp`n'rating if dp`n'=="`donor'"
			replace rating_`donor'=0 if rating_`donor'==.
			label var rating_`donor' `donor'		
			replace mention_`donor'=1 if dp`n'=="`donor'"
			label var mention_`donor' `donor'
			replace time_`donor'=dp`n'time if dp`n'=="`donor'"
			lab values time_`donor' time
			label var time_`donor' `donor'		
		} 
	}
	
	renvars mention_* rating_* time_* , lower

	label var mention_world_bank "World Bank"	
	label var mention_dfid "FCDO"
	
	//identify too much time for each donor
	foreach var of varlist time_*{
		gen toomuch_`var'=(`var'==2)
		}
	egen donors_too_much_time=rowmax(toomuch*)
	
* -------------------------------------------------------------------		
// 10.	Donor advice satisfaction:
* -------------------------------------------------------------------
	
	// New variable labels
	lab var advice_exams 		"Advice_Exams"
	lab var advice_curric 		"Advice_Curriculum"
	lab var advice_textbooks 	"Advice_Textbooks"
	lab var advice_teachers 	"Advice_Teachers"
	lab var advice_private 		"Advice_Private Schools"

	// Create numerical scale of advice
	foreach var of varlist advice_exams advice_curric advice_textbooks advice_teachers advice_private{
	encode `var',gen(`var'_num)
	}
	
	// Rescale advice numerical values
	foreach var of varlist advice_*num {
		 recode `var' 4=1 3=0.5 2=0 1=1
		 } 
	
	// Principal component analysis:
	pca advice_exams_num advice_curric_num advice_textbooks_num advice_teachers_num advice_private_num
	tempvar advice_pca
	predict `advice_pca'
	egen advice=std(`advice_pca')
	impute advice advice_exams_num advice_curric_num advice_textbooks_num advice_teachers_num advice_private_num, gen(imputed_advice)
	replace advice=imputed_advice if advice==.
	
* -------------------------------------------------------------------		
// 11. Statement of priority projects:
* -------------------------------------------------------------------	

	//keep only the top 3
	foreach var of varlist priority_construction priority_foundational priority_ppp priority_computers priority_tvet {
		recode `var' 1=3 2=2 3=1 4=. 5=. 6=.
		}

	label var priority_construction "School Construction"
	label var priority_foundational "Foundational Literacy"
	label var priority_ppp 			"Public-private partnership"
	label var priority_computers 	"Computers / Technology"
	label var priority_tvet 		"TVET"
	label var priority_other 		"Other (Specify)"

	// Chose any of these project options as priorities
	gen anypriority=. 
	foreach var of varlist priority_construction priority_foundational priority_ppp priority_computers priority_tvet{
	replace anypriority=1 if `var'!=.
	gen `var'_bin=(inlist(`var',1,2,3))
	}
	
	//Binary for each priority
	foreach var of varlist priority_construction priority_foundational priority_ppp priority_computers priority_tvet{
		gen `var'_binary=(`var'!=.)*100
	}

	label var priority_tvet_binary 			"TVET" 
	label var priority_computers_binary 	"Computers / Technology"
	label var priority_foundational_binary 	"Foundational Literacy"
	label var priority_construction_binary 	"School construction"
	label var priority_ppp_binary 			"Public-private partnership"
	
	// order of priority (first, second and third most important)
foreach var of varlist priority_construction priority_foundational priority_ppp priority_computers priority_tvet{
	gen 	`var'_top=0
	replace `var'_top=1 if `var'==1
	gen 	`var'_2nd=0
	replace `var'_2nd=1 if `var'==2	
	gen 	`var'_3rd=0
	replace `var'_3rd=1 if `var'==3	
	gen 	`var'_top3=0
	replace `var'_top3=100 if inlist(`var',1,2,3)	
}

	label var priority_construction_top "School Construction"
	label var priority_foundational_top "Foundational Literacy"
	label var priority_ppp_top 			"Public-private partnership"
	label var priority_computers_top 	"Computers / Technology"
	label var priority_tvet_top 		"TVET"	
	
* -------------------------------------------------------------------		
// 12. Ideas and sources on education policy
* -------------------------------------------------------------------	

	split idea_source, p(",")
	gen idea_int_uni=0
	gen idea_loc_uni=0
	gen idea_news=0
	gen idea_none=0
	gen idea_other=0
	gen idea_social=0
	gen idea_unesco=0
	gen idea_unicef=0
	gen idea_world_bank=0

	forval n = 1/8{
	replace idea_source`n'=proper(idea_source`n')
	replace idea_int_uni=1 	if idea_source`n'=="International Universities"
	replace idea_loc_uni=1 	if idea_source`n'=="Local Universities"
	replace idea_news=1 	if idea_source`n'=="Newspapers"
	replace idea_none=1 	if idea_source`n'=="None Of The Above"
	replace idea_other=1 	if idea_source`n'=="Other (Please Specify)"
	replace idea_social=1 	if idea_source`n'=="Social Media"
	replace idea_unesco=1 	if idea_source`n'=="Unesco Reports"
	replace idea_unicef=1 	if idea_source`n'=="Unicef Reports"
	replace idea_world_bank=1 if idea_source`n'=="World Bank Reports"
	}

	label var idea_int_uni    "International Universities"
	label var idea_loc_uni    "Local Universities"
	label var idea_news       "Newspapers"
	label var idea_none       "None of the above"
	label var idea_other      "Other"
	label var idea_social     "Social Media"
	label var idea_unesco     "UNESCO Reports"
	label var idea_unicef     "UNICEF Reports"
	label var idea_world_bank "World Bank Reports"

	label var idea_source "Sources for ideas" 
	
* -------------------------------------------------------------------		
// 13. Country context	- knowledge of government spending, learning levels 
//	and years of schooling (eyos)
* -------------------------------------------------------------------	
	
	label var kn_spending   "Knowledge - Government Spending" 
	lab var kn_learning 	"Estimate of Learning"
	lab var kn_eyos 		"Belief about average schooling (years)"
	
	// Continuous values of Government spending with education
	gen 	kn_spending_cont=50  if kn_spending=="Under $100"
	replace kn_spending_cont=175 if kn_spending=="Between $100 - $250"
	replace kn_spending_cont=375 if kn_spending=="Between $251 - $500"
	replace kn_spending_cont=625 if kn_spending=="Between $500 - $750"
	replace kn_spending_cont=875 if kn_spending=="Over $750"

	// Categorical values of Government spending with education	
	gen 	kn_spending_cat=1 if kn_spending=="Under $100"
	replace kn_spending_cat=2 if kn_spending=="Between $100 - $250"
	replace kn_spending_cat=3 if kn_spending=="Between $251 - $500"
	replace kn_spending_cat=4 if kn_spending=="Between $500 - $750"
	replace kn_spending_cat=5 if kn_spending=="Over $750"
	
	label define kn_spending_cat 1 "Under $100" 2 "Between $100 - $250" 3 "Between $251 - $500" 4 "Between $500 - $750" 5 "Over $750"
	label values kn_spending_cat kn_spending_cat

	// Learning poverty in std
	egen 	learning=std(kn_learning)
	replace learning=0 if learning==.
	lab var learning "Belief about foundational learning levels (z-score)"

* -------------------------------------------------------------------		
// 13. Growth Mindset 
* -------------------------------------------------------------------		

	foreach var of varlist growth* {
	rename `var' `var'_s
	encode `var'_s, gen(`var')
	recode `var' 1=3 2=4 3=2 4=5 5=1
	label val `var' "likert"
	}

	gen 	growth_pisa=0 if inlist(growth2,3,4,5)
	replace growth_pisa=1 if inlist(growth2,1,2)
	
	foreach var of varlist growth1 growth2 growth3{
	recode `var'  1=6 2=5 3=3.5 4=2 5=1
	}

	lab define growth 1 "Strongly Agree" 2 "Agree" 5 "Disagree" 6 "Strong Disagree"
	lab values growth1 growth2 growth3 growth

	lab var growth1 "People have a certain amount of intelligence, and can’t really do much to change it"
	lab var growth2 "People's intelligence is something that you can’t change very much"
	lab var growth3 "People can learn new things, but you can’t really change basic intelligence"
		
	egen 	growth=rowmean(growth1 growth2 growth3)
	lab var growth "Growth Mindset (1-6 score)"
	
	global descriptive_6 reform* advice_* rolemodel* idea* frag* priority* anypriority conclusion* kn_* growth* dp* rating_* mention* time* 

* -------------------------------------------------------------------		
// 14. Comparison across themes for correlation:
* -------------------------------------------------------------------			

	egen found_index=rowmean(sdg_found_top3 priority_foundational_binary)
	egen tvet_index=rowmean(sdg_tvet_top3 priority_tvet_binary)

	tab priority_foundational, gen(pf) 
	tab sdg_found, gen(sf)
	tab priority_tvet, gen(pt) 
	tab sdg_tvet, gen(st)
	tab sdg_empl, gen(se) 
	tab sdg_sust, gen(ss)

	foreach var of varlist pt? st? pf? sf? se? ss?{
	replace `var'=0 if `var'==.
	}

	pca pf? sf?
	predict found_pca
	egen found_index2=std(found_pca)

	pca pt? st? se? ss?
	predict tvet_pca
	egen tvet_index2=std(tvet_pca)

	pca     growth script_posterior
	predict beliefs_int_unstd
	egen 	beliefs_int=std(beliefs_int_unstd)

	replace beliefs_int=0 if beliefs_int==.
	lab var beliefs_int "Belief about interventions (Index)"

	drop __000000 __000001

* -------------------------------------------------------------------		
// Globals
* -------------------------------------------------------------------		

// (IIIC) Globals
global meta startdate_1 enddate_1 startdate_2 enddate_2 progress durationinseconds finished recordeddate googlelist online responseid responseid2 resp_id male current_emp agencyid country_id region regioncode jobtitle titlecode lang_english lang_french
order $meta 

* -------------------------------------------------------------------		
// Additional variables for regressions + labelling
* -------------------------------------------------------------------	

	xtile   lowexp=experience, n(2)
	recode  lowexp 2=0
	lab var lowexp "Under 10 years experience"

	gen 	agency2=0
	replace agency2=1 if agencyid==5
	lab var agency2 "TVET/Skills Ministry/Agency"
	
	gen 	minister=0
	replace minister=1 if titlecode==5
	lab var minister "Minister"
	
	lab var lang_english "English Speaking"
	lab var lang_french "French Speaking"
	lab var lowexp "\(<\)10 years of experience"

	lab var agencyid "Agency (Numeric)"
	lab var titlecode "Job title (Numeric)" 
	lab var regioncode "World Region"

	gen 	signal=2 if inlist(treat_script_country,0,1)
	replace signal=4 if treat_script_country==2
	
	gen 	rcttreatXstudiedoecd=treat_script_rct*studied_oecd
	lab var rcttreatXstudiedoecd "RCT X Studied in OECD"

	gen 	rcttreatXmale=treat_script_rct*male
	lab var rcttreatXmale "RCT X Male"
		
	gen 	update_binary=0 if inlist(updating,-2,-1,0)	
	replace update_binary=1 if inlist(updating,1,2,3)
		 
	save "$root/output/analysis_finaldataset_withtitles.dta", replace 
	
* -------------------------------------------------------------------		
// Save version without job titles 
* -------------------------------------------------------------------	

	drop jobtitle titlecode
	
	mmerge country_id using "$root/input/country_id_lookup.dta"	
	mmerge countrycode using "$root/input/worldbank.dta" 
	drop if _merge==2
	
	gen rcts30=(rcts>=30)
	gen treatXrcts30=treat_script_rct*rcts30
	lab var rcts30 "30+ RCTs"
	lab var treatXrcts30 "Study RCT x 30+ RCTs"
		
	save "$root/output/analysis_finaldataset.dta", replace 
	